package metadata

import (
	"errors"
	"strings"

	"git.cloud.inspur.com/ichain/ichain-sdk-go/pkg/core/logging/api"
)

var levelNames = []string{
	"CRITICAL",
	"ERROR",
	"WARNING",
	"INFO",
	"DEBUG",
}

func ParseLevel(level string) (api.Level, error) {
	for i, name := range levelNames {
		if strings.EqualFold(name, level) {
			return api.Level(i), nil
		}
	}
	return api.ERROR, errors.New("logger: invalid log level")
}

func ParseString(level api.Level) string {
	return levelNames[level]
}
